import  React from 'react';
import BreadcrumbCustom from '../BreadcrumbCustom';
import {Row} from 'antd';
import WrappedRoleForms from "./RoleForms";

export default class RoleAddOrEdit extends  React.Component {

    constructor(props){
        super(props);
        this.state = {
            title: '新增角色',
            disabled: false,
            id: null,
            cancel:this.cancel,
            pagination:undefined
        };
    }

    componentWillMount(){
        const macth = this.props.match;
        if(macth.params.id != undefined){
            const isEdit = macth.url.indexOf('edit') != -1;
            this.setState({
                disabled:!isEdit,
                id:macth.params.id,
                title:isEdit ? '编辑角色':'角色详情',
            });
        }

    }

    componentWillUnmount() {
        this.setState = (state, callback) => {
            return;
        };
    }
    cancel = () => {
        this.props.history.push({
            pathname:'/app/system/roles',
            state:this.props.location.state,
        });
    }

    render(){
        return (
            <div>
                <BreadcrumbCustom  first={this.state.title}/>
                <Row gutter={16}>
                    <WrappedRoleForms
                        disabled={this.state.disabled}
                        id={this.state.id}
                        cancel={this.state.cancel}/>
                </Row>
            </div>
        );
    };
}